A D2D communication technology is a technology in which devices directly communicate with each other. Different from that in a cellular communication technology, data of a transmit device does not need to be transmitted to a receive device using a base station, but is directly transmitted using an air interface between the transmit device and the receive device. Therefore, a forwarding delay of the base station is reduced. A typical application scenario of the D2D communication technology is a public security scenario such as communication between firemen. A typical service of the D2D communication technology is a voice service. In a D2D communication process, a device always needs to know a distance between the device and another device that communicates with the device. For example, in a public security scenario, a fireman needs to know a distance between the fireman and another fireman, and in an advertisement discovery scenario, an advertisement receiver needs to know a distance between the advertisement receiver and an advertisement publisher.
In other approaches, a D2D transmission distance obtaining method includes a receive device receives information sent by a transmit device, detects receive power of the information, and then estimates a distance from the transmit device to the receive device according to the receive power. In the foregoing D2D transmission distance obtaining method, only impact exerted on receive power by a D2D transmission distance is considered, and then a distance from a transmit device to a receive device is calculated according to the receive power without considering impact exerted on the receive power by another factor. Therefore, the D2D distance obtained using the foregoing method is inaccurate.